package backend.service.admin;

import backend.model.admin.Department;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl extends DBModelServiceImpl<Department> implements DepartmentService {

    @Override
    public Class<Department> getEntityClass() {
        return Department.class;
    }

    @Override
    public List<Department> findAllDepartments() {
        return dbModelDao.findByNamedQuery("findAllDepartments");
    }

    @Override
    public List<Department> findAllActiveDepartments() {
        return dbModelDao.findByNamedQuery("findAllActiveDepartments");
    }

    @Override
    public Department findDepartmentByName(String name) {
        List<Department> departmentsByName = dbModelDao.findByNamedQueryAndParams("findDepartmentByName", new String[]{"name"}, new Object[]{name});
        assert departmentsByName.size() <= 1;
        if (departmentsByName.size() == 1) {
            return departmentsByName.get(0);
        }
        return null;
    }
}
